package com.soft.servlet;

import com.soft.entity.Order;
import com.soft.entity.UserInfo;
import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author kongz
 * @version 1.0 2021/6/8 9:43
 * @description 显示用户所有订单信息
 */
@WebServlet(name = "OrderListServlet", urlPatterns = "/OrderList")
public class OrderListServlet extends HttpServlet {
    private Domain domain;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        domain = new Domain();
        UserInfo ui = null;
        if (req.getSession().getAttribute("user") != null) {
            ui = (UserInfo) req.getSession().getAttribute("user");
            List<Order> list = domain.getOrderByBuyer(ui.getId());
            req.setAttribute("OrderList", list);
            req.getRequestDispatcher("dingdan.jsp").forward(req, resp);
        } else {
            req.getSession().setAttribute("flag", 11);
            resp.sendRedirect("denglu.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
